/*
 * Ext GWT - Ext for GWT
 * Copyright(c) 2007-2009, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */
package web.mail.client.ui;

import java.util.List;

import web.app.client.model.Folder;

import com.extjs.gxt.ui.client.data.BaseTreeLoader;
import com.extjs.gxt.ui.client.data.TreeModelReader;
import com.extjs.gxt.ui.client.store.TreeStore;
import com.extjs.gxt.ui.client.util.IconHelper;
import com.extjs.gxt.ui.client.widget.treepanel.TreePanel;

public class MailFolderPanel extends TreePanel<Folder> {

  public MailFolderPanel() {
    super(             
       new TreeStore<Folder>(
            new BaseTreeLoader<Folder>(
                new TreeModelReader<List<Folder>>()
            )
       )
    );

    getStyle().setLeafIcon(IconHelper.createStyle("tree-folder"));
    setDisplayProperty("name");
    setAutoSelect(true);
  }

  public void load( Folder f ){
	  Folder selection = getSelectionModel().getSelectedItem();
      loader.load( f );
      getSelectionModel().select(selection, true);
  }

  
/*
  protected void handleEvent(AppEvent event) {
    if (event.getType() == AppEvents.NavMail) {
      Folder f = event.getData();
      if (f != null) {
        loader.addListener(Loader.Load, new LoadListener() {
          @Override
          public void loaderLoad(LoadEvent le) {
            loader.removeLoadListener(this);
          }
        });
        loader.load(f);
      }
    }
  }*/
}
